package com.cnzz.site1255174697.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;


/**
 * 项目名称：MEN
 * 类描述：
 * 创建人：cheng
 * 创建时间：2016/5/25 6:11
 * 修改人：cheng
 * 修改时间：2016/5/25 6:11
 * 修改备注：
 */
public class WebViewUtils {

    public static void seWebSettingst(WebView webView) {
        WebSettings webseting = webView.getSettings();
//        webseting.setDomStorageEnabled(true);
//        webseting.setAppCacheMaxSize(1024 * 1024 * 8);//设置缓冲大小，我设的是8M
//        String appCacheDir = webView.getContext().getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
//        webseting.setAppCachePath(appCacheDir);
        webseting.setDefaultTextEncodingName("UTF-8");
        webseting.setAllowFileAccess(true);
        webseting.setAppCacheEnabled(true);
//自适应屏幕
        webseting.setCacheMode(WebSettings.LOAD_DEFAULT);
        webseting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//        webseting.setRenderPriority(WebSettings.RenderPriority.HIGH);//提高渲染的优先级
//        webView.getSettings().setBlockNetworkImage(true);//把图片加载放在最后来加载渲染
        // 开启 DOM storage API 功能
        webseting.setDomStorageEnabled(true);
        webseting.setJavaScriptEnabled(true);
// 设置可以支持缩放
        webseting.setSupportZoom(true);
//扩大比例的缩放
        webseting.setUseWideViewPort(true);
        webseting.setLoadWithOverviewMode(true);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url); //在当前的webview中跳转到新的url
                return true;
            }
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }
        });
    }
}
